package leo.game.ui
{
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.text.TextField;
	
	import ghostcat.util.easing.TweenUtil;
	
	import leo.data.GameConfig;
	import leo.data.GameConst;
	import leo.data.GameModel;
	import leo.manager.McMannager;

	/**
	 * 顶部ui 
	 * @author leo
	 * 
	 */	
	public class UITop extends Sprite
	{
		private static var _instance :UITop = null;
		/**
		 * 顶部ui 
		 */		
		public var topUI :MovieClip;
		/**
		 * 等级显示 
		 */		
		public var txtLevel :TextField;
		/**
		 * 金币显示 
		 */		
		public var txtGold :TextField;
		public function UITop()
		{
			super();
			init();
		}
		/**
		 * 更新金币数量 
		 * @param value 值
		 * @param isAdd 是否是加金币，为false就为扣减
		 * 
		 */	
		public function updateGold(value :int,isAdd :Boolean):void
		{
			if(isAdd)
			{
				GameModel.instance.curGameGold += value;
				var addGold :int = GameModel.instance.curGameGold;
				this.txtGold.text = addGold.toString();
			}else
			{
				GameModel.instance.curGameGold -= value;
				var subGold :int = GameModel.instance.curGameGold;
				this.txtGold.text = subGold.toString();
			}
			
		}
		/**
		 * 更新等级
		 * @param value
		 * 
		 */		
		public function updateLevel(value :int):void
		{
			if(value)
			{
				this.txtLevel.text = "关卡" + (value + 1).toString();
			}
		}
		/**
		 * 显示顶部ui 
		 * @param duration
		 * @param tx
		 * @param ty
		 * 
		 */		
		public function showUITop(duration :int, tx :int, ty :int):void
		{
			TweenUtil.to(this,duration,{x :tx, y :ty});
		}
		
		private function init():void
		{
			var name :String = GameConst.TOP_UI;
			this.topUI = McMannager.instance.getMCByName(name);
			this.addChild(this.topUI);
			
			this.txtLevel = this.topUI.levelUI.txtLevel;
			this.txtGold = this.topUI.goldUI.txtGold;
			
			this.txtLevel.text = "关卡" + (GameModel.instance.curLevel + 1);
			this.txtGold.text = GameConfig.def_gold.toString();
			GameModel.instance.curGameGold = GameConfig.def_gold;
		}

		public static function get instance():UITop
		{
			if(_instance == null)
			{
				_instance = new UITop();
			}
			return _instance;
		}

	}
}